package com.ahwei.common.rest.base;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @Author：ahWei Email: ahwei163@qq.com
 * Date: 2022-03-09 17:34:33
 * Description: 这是一个Java文件！
 */
@Data
@Accessors(chain = true)
@Schema(description = "分页描述")
public class PageVo<T> implements Serializable {
    /**
     * 每页条数  AppContext.PAGE_COUNT;
     */
    @Schema(example = "5", description = "每页显示数据条数")
    private Integer pageSize = 5;
    /**
     * 当前页数;
     */
    @Schema(example = "1", description = "当前页数")
    private Integer currentPage = 1;
    /**
     * 最大页数
     */
    @Schema(example = "100", description = "最大页数")
    private Integer pages = 1;
    /**
     * 总数据条数
     */
    @Schema(example = "600", description = "总数据条数")
    private Integer total;
    /**
     * 查询到的数据
     */
    @Schema(example = "data", description = "查询到的数据")
    private List<T> dataList;
    /**
     * 是否为第一页
     */
    @Schema(example = "min", description = "是否为第一页")
    private boolean isFirstPage;
    /**
     * 是否为最后一页
     */
    @Schema(example = "max", description = "是否为最后一页")
    private boolean isLastPage;

    public PageVo() {
    }

    public PageVo(List<T> dataList, long currentPage, long pageSize, long total, long pages) {
        this.dataList = dataList;
        this.pageSize = (int) pageSize;
        this.currentPage = (int) currentPage;
        this.total = (int) total;
        this.pages = (int) pages;
        this.isFirstPage = (currentPage == 1);
        this.isLastPage = (currentPage == this.pages);
    }
}
